<%--
  Created by IntelliJ IDEA.
  User: hongcy
  Date: 16-3-21
  Time: 下午2:45
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/include/taglib.jsp"%>
<% boolean isLoginError = request.getParameterMap().containsKey("login_error") ; %>
<!DOCTYPE html>
<html>
<head>
    <title>欢迎登录新西兰管理平台</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link href="${cdnContentPath}/static/bootstrap-3.3.5/css/bootstrap.min.css" rel="stylesheet">
    <link href="${cdnContentPath}/static/bootstrap-3.3.5/css/datepicker3.css" rel="stylesheet">
    <link href="${cdnContentPath}/static/bootstrap-3.3.5/css/styles.css" rel="stylesheet">
    <!--[if lt IE 9]>
    <script src="${cdnContentPath}/static/bootstrap-3.3.5/js/html5shiv.min.js"></script>
    <script src="${cdnContentPath}/static/bootstrap-3.3.5/js/respond.min.js"></script>
    <![endif]-->
    <script type="text/javascript">
        var ML = {
            alert: function (code, content) {
                var msg = [];
                if (code) {
                    msg.push(code);
                }
                if (content) {
                    msg.push(content);
                }
                alert(msg.join(":"));
            },
            defaultVal: function (val, defaultVal) {
                return val || defaultVal;
            }
        };
    </script>
</head>
<body>
    <div class="alert alert-info alert-dismissable" style="color:red ;text-align: center; display:none" id="error">
        <button type="button" class="close" data-dismiss="alert" aria-hidden="true">
            ×
        </button>
        账号或密码错误，请重试！
    </div>
    <div class="row" style="width:100%">
        <div class="col-xs-10 col-xs-offset-1 col-sm-8 col-sm-offset-2 col-md-4 col-md-offset-4">
            <div class="login-panel panel panel-default">
                <div class="panel-heading">登录</div>
                <div class="panel-body">
                    <form id="form-login" role="form" action="/mulanweb/common/login_out/login" method="post">
                        <fieldset>
                            <div class="form-group">
                                <input class="form-control" placeholder="帐号" name="username" id="username" type="text" autofocus="">
                            </div>
                            <div class="form-group">
                                <input class="form-control" placeholder="密码" name="password" id="password" type="password" value="" onkeydown="return keydown(event)">
                            </div>
                            <a id="btn-login" href="#" class="btn btn-primary">登录</a>
                        </fieldset>
                    </form>
                </div>
            </div>
        </div><!-- /.col-->
    </div><!-- /.row -->
    <script src="${cdnContentPath}/static/jquery/jquery-3.1.0.min.js"></script>
    <script src="${cdnContentPath}/static/bootstrap-3.3.5/js/bootstrap.min.js"></script>
    <script type="text/javascript">
        function keydown(e){
            if(e.keyCode==13){
                $("#btn-login").click() ;
            }
        }
        $(document).ready(function () {
            // 登陆页面要在最顶层窗口展示
            if(window.parent.location.href != window.location.href) {
                window.parent.location.href = window.location.href;
                return;
            }

            <%if (isLoginError) {%>
                $("#error").css("display","block") ;
            <%}%>
            var $username = $("#username"), $password = $("#password");
            $(document).on("keypress blur", "#username", function () {
                if ($username.val()) {
                    $username.parent().removeClass("has-error");
                } else {
                    $username.parent().addClass("has-error");
                }
            }).on("keypress blur", "#password", function () {
                if ($password.val()) {
                    $password.parent().removeClass("has-error");
                } else {
                    $password.parent().addClass("has-error");
                }
            }).on("click", "#btn-login", function () {
               var username = $username.val(), password = $password.val();
               if (!username) {
                   $username.parent().addClass("has-error").focus();
                   return false;
               } else {
                   $username.parent().removeClass("has-error");
               }
               if(!password) {
                   $password.parent().addClass("has-error").focus();
                   return false;
               } else {
                   $password.parent().removeClass("has-error");
               }

               $("#form-login").submit();
            })
        });
    </script>
</body>
</html>
